package it.mp.multitask.utility;

import it.mp.multitask.bean.App;

import java.io.Serializable;
import java.util.Comparator;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

public class AppComparator implements Serializable, Comparator<App> {
	private PackageManager pm=null;
	private static final long serialVersionUID = -6700403096228788434L;

	public AppComparator(PackageManager pm){
		this.pm=pm;
	}
	
	public int compare(App rtInfo1, App rtInfo2) {
		String app1=null;
		String app2=null;
		try {
			app1 = (String) pm.getApplicationLabel(pm.getApplicationInfo(rtInfo1.getPackageName(), 0));
			app2=(String) pm.getApplicationLabel(pm.getApplicationInfo(rtInfo2.getPackageName(), 0));
		} catch (NameNotFoundException e) {
		}
		if (app1==null){
			return 0;
		}else{
			return app1.compareTo(app2);
		}
	}


}
